home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4838 / 4838.xpi / chrome / multipletab.jar / content / multipletab / lib / extensions.js < prev    next >
Encoding:
JavaScript  |  2010-02-03  |  3.7 KB  |  129 lines

  1. /*
  2.  Extensions Compatibility Library
  3.  
  4.  Usage:
  5.    if (window['piro.sakura.ne.jp'].extensions.isAvailable('my.extension.id@example.com'))
  6.        window['piro.sakura.ne.jp'].extensions.goToOptions('my.extension.id@example.com');
  7.    // just same to:
  8.    // if (window['piro.sakura.ne.jp'].extensions.isInstalled('my.extension.id@example.com') &&
  9.    //     window['piro.sakura.ne.jp'].extensions.isEnabled('my.extension.id@example.com'))
  10.    //     window['piro.sakura.ne.jp'].extensions.goToOptions('my.extension.id@example.com');
  11.    var dir = window['piro.sakura.ne.jp'].extensions.getInstalledLocation('my.extension.id@example.com');
  12.  
  13.  lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
  14.    http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
  15.  original:
  16.    http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/extensions.js
  17. */
  18. (function() {
  19.     const currentRevision = 4;
  20.  
  21.     if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
  22.  
  23.     var loadedRevision = 'extensions' in window['piro.sakura.ne.jp'] ?
  24.             window['piro.sakura.ne.jp'].extensions.revision :
  25.             0 ;
  26.     if (loadedRevision && loadedRevision > currentRevision) {
  27.         return;
  28.     }
  29.  
  30.     const Cc = Components.classes;
  31.     const Ci = Components.interfaces;
  32.  
  33.     window['piro.sakura.ne.jp'].extensions = {
  34.         revision : currentRevision,
  35.  
  36.         ExtensionManager : Cc['@mozilla.org/extensions/manager;1']
  37.             .getService(Ci.nsIExtensionManager),
  38.         RDF : Cc['@mozilla.org/rdf/rdf-service;1']
  39.             .getService(Ci.nsIRDFService),
  40.         WindowMediator : Cc['@mozilla.org/appshell/window-mediator;1']
  41.             .getService(Ci.nsIWindowMediator),
  42.         Prefs : Cc['@mozilla.org/preferences;1']
  43.             .getService(Ci.nsIPrefBranch),
  44.  
  45.         isAvailable : function(aId)
  46.         {
  47.             return (this.isInstalled(aId) && this.isEnabled(aId)) ? true : false ;
  48.         },
  49.  
  50.         isInstalled : function(aId)
  51.         {
  52.             return this.ExtensionManager.getInstallLocation(aId) ? true : false ;
  53.         },
  54.  
  55.         getInstalledLocation : function(aId)
  56.         {
  57.             var location = this.ExtensionManager.getInstallLocation(aId);
  58.             return location ? location.location : null ;
  59.         },
  60.  
  61.         isEnabled : function(aId)
  62.         {
  63.             var res  = this.RDF.GetResource('urn:mozilla:item:'+aId);
  64.             var appDisabled = false;
  65.             try {
  66.                 appDisabled = this.ExtensionManager.datasource.GetTarget(
  67.                         res,
  68.                         this.RDF.GetResource('http://www.mozilla.org/2004/em-rdf#appDisabled'),
  69.                         true
  70.                     ).QueryInterface(Ci.nsIRDFLiteral)
  71.                     .Value == 'true';
  72.             }
  73.             catch(e) {
  74.             }
  75.             var userDisabled = false;
  76.             try {
  77.                 userDisabled = this.ExtensionManager.datasource.GetTarget(
  78.                         res,
  79.                         this.RDF.GetResource('http://www.mozilla.org/2004/em-rdf#userDisabled'),
  80.                         true
  81.                     ).QueryInterface(Ci.nsIRDFLiteral)
  82.                     .Value == 'true';
  83.             }
  84.             catch(e) {
  85.             }
  86.  
  87.             return !appDisabled && !userDisabled;
  88.         },
  89.  
  90.         goToOptions : function(aId)
  91.         {
  92.             var res  = this.RDF.GetResource('urn:mozilla:item:'+aId);
  93.             var uri;
  94.             try {
  95.                 uri = this.ExtensionManager.datasource.GetTarget(
  96.                         res,
  97.                         this.RDF.GetResource('http://www.mozilla.org/2004/em-rdf#optionsURL'),
  98.                         true
  99.                     ).QueryInterface(Ci.nsIRDFLiteral)
  100.                     .Value;
  101.             }
  102.             catch(e) {
  103.             }
  104.             if (!uri) return;
  105.  
  106.             var windows = this.WindowMediator.getEnumerator(null);
  107.             while (windows.hasMoreElements())
  108.             {
  109.                 let win = windows.getNext();
  110.                 if (win.location.href == uri) {
  111.                     win.focus();
  112.                     return;
  113.                 }
  114.             }
  115.             var instantApply = false;
  116.             try {
  117.                 instantApply = this.Prefs.getBoolPref('browser.preferences.instantApply');
  118.             }
  119.             catch(e) {
  120.             }
  121.             window.openDialog(
  122.                 uri,
  123.                 '',
  124.                 'chrome,titlebar,toolbar,centerscreen,' + (instantApply ? 'dialog=no' : 'modal' )
  125.             );
  126.         }
  127.     };
  128. })();
  129.